package project.youkumenu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import project.youkumenu.customview.ClearWriteEditText;
import project.youkumenu.utils.UIHandler;

public class MainActivity extends AppCompatActivity {

    ClearWriteEditText mEtAccount;

    private UIHandler<Activity> mHandler = new UIHandler<Activity>(this) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if (null != getWeakReference()) {
                // TODO: 2018/3/8
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mEtAccount = (ClearWriteEditText) findViewById(R.id.login_et_name);
        clickListener();
    }

    private boolean checkInput(String phone) {
        if (TextUtils.isEmpty(phone)) {
            mEtAccount.setShakeAnimation();
            Toast.makeText(this, "账号不能为空", Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    private void loginCommit() {
        String account = mEtAccount.getText().toString();
        if (checkInput(account)) {
            //TODO:请求服务端注册账号

        }
    }

    private void clickListener() {
        Button btn = (Button) findViewById(R.id.btn_register);
        Button btn_activity = (Button) findViewById(R.id.btn_go_new_activity);
        Button btn_fragment = (Button) findViewById(R.id.btn_go_new_fragment);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                loginCommit();
            }
        });
        btn_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, NewActivity.class));
            }
        });
        btn_fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, Main2Activity.class));
            }
        });
    }

}
